﻿package algorithm;

import java.util.ArrayList;
import java.util.HashMap;

import bean.Sports_record;

import java.util.List;
import java.util.Map;
public class Sportscredit_ranking {
	
	//输出函数
	public Map<String,List<Sports_record>> Get_Ranking(List<Sports_record> list){
		Map<String,List<Sports_record>> outputmap = new HashMap<String,List<Sports_record>>();
		outputmap.put("swimming", swimming(list)); 
		outputmap.put("basketball",basketball(list));
		outputmap.put("running", running(list));
		return outputmap;
	}	
	
	

	private List<Sports_record> basketball(List<Sports_record> list){
		List<Sports_record> inputlist = new ArrayList<Sports_record>();
		List<Sports_record> templist = new ArrayList<Sports_record>();
		for(int i = 0;i < list.size();i++){
			inputlist.add(list.get(i));
		}
		templist.add(0,inputlist.get(0));
		for(int i = 0;i < inputlist.size();i++){
			for(int j = 0;j < inputlist.size();j++){
				if(inputlist.get(i).getBasketball_record() > inputlist.get(j).getBasketball_record()){
					templist.set(0, inputlist.get(i));
					inputlist.set(i, inputlist.get(j));
					inputlist.set(j, templist.get(0));
				}
			}
		}
	
		return inputlist;
	}
	
	private List<Sports_record> swimming(List<Sports_record> list){
		List<Sports_record> inputlist = new ArrayList<Sports_record>();
		List<Sports_record> templist = new ArrayList<Sports_record>();
		for(int i = 0;i < list.size();i++){
			inputlist.add(list.get(i));
		}
		templist.add(0,inputlist.get(0));
		for(int i = 0;i < inputlist.size();i++){
			for(int j = 0;j < inputlist.size();j++){
				if(inputlist.get(i).getSwimming_record() > inputlist.get(j).getSwimming_record()){
					templist.set(0, inputlist.get(i));
					inputlist.set(i, inputlist.get(j));
					inputlist.set(j, templist.get(0));
				}
			}
		}
		
		return inputlist;
	}
	
	private List<Sports_record> running(List<Sports_record> list){
		List<Sports_record> inputlist = new ArrayList<Sports_record>();
		List<Sports_record> templist = new ArrayList<Sports_record>();
		for(int i = 0;i < list.size();i++){
			inputlist.add(list.get(i));
		}
		templist.add(0,inputlist.get(0));
		for(int i = 0;i < inputlist.size();i++){
			for(int j = 0;j < inputlist.size();j++){
				if(inputlist.get(i).getRunning_record() > inputlist.get(j).getRunning_record()){
					templist.set(0, inputlist.get(i));
					inputlist.set(i, inputlist.get(j));
					inputlist.set(j, templist.get(0));
				}
			}
		}
		
		return inputlist;
	}
}

